//
//  TG_UIHelper.m
//  TongGuanLease
//
//  Created by 张奇 on 2022/4/12.
//

#import "TG_UIHelper.h"

@implementation TG_UIHelper

+ (instancetype)sharedInstance
{
    static TG_UIHelper *instance = nil;
    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{
        instance = [[TG_UIHelper alloc] init];
    });
    return instance;
}
+ (UIFont *)fontOfSize:(int)font
{
    if (IS_IPHONE_4_OR_LESS || IS_IPHONE_5) {
        return [UIFont systemFontOfSize:0.853*font];
    } else if (IS_IPHONE_6) {
        return [UIFont systemFontOfSize:font];
    } else if (IS_IPHONE_6P) {
        return [UIFont systemFontOfSize:1.104*font];
    }
    return [UIFont systemFontOfSize:font];
}
+ (CGFloat)autoHeight:(CGFloat)f {
    if (IS_IPHONE_4_OR_LESS || IS_IPHONE_5) {
        return f;
    } else if (IS_IPHONE_6) {
        return f;
    } else if (IS_IPHONE_6P) {
        return 1.104*f;
    }
    return f;
}
+ (UIFont *)TGAutoFount:(CGFloat)f name:(NSString *)name {
    
    UIFont *font = [UIFont fontWithName:name size:AdaptedWidthValue(f)];
    if (font == nil) {
        font = [UIFont systemFontOfSize:AdaptedWidthValue(f)];
    }
    return font;
}

+ (UIFont *)boldFontOfSize:(int)font
{
    if (IS_IPHONE_4_OR_LESS || IS_IPHONE_5) {
        return  [UIFont boldSystemFontOfSize:0.853*font];
    } else if (IS_IPHONE_6) {
        return [UIFont boldSystemFontOfSize:font];
    } else if (IS_IPHONE_6P) {
        return [UIFont boldSystemFontOfSize:1.104*font];
    }else if (IS_IPHONEX){
        
    }
    return [UIFont boldSystemFontOfSize:font];
}

+ (BOOL)isIphoneX {
    BOOL iPhoneXSeries = NO;
    if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
        return iPhoneXSeries;
    }
    if (@available(iOS 11.0, *)) {
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        if (mainWindow.safeAreaInsets.bottom > 0.0) {
            iPhoneXSeries = YES;
        }
    }
    return iPhoneXSeries;
    /*
     struct utsname systemInfo;
     uname(&systemInfo);
     NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
     if ([platform isEqualToString:@"i386"] || [platform isEqualToString:@"x86_64"]) {
     // judgment by height when in simulators
     return (CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(375, 812)) ||
     CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(812, 375)));
     }
     BOOL isIPhoneX = [platform isEqualToString:@"iPhone10,3"] || [platform isEqualToString:@"iPhone10,6"];
     return isIPhoneX;
     */
}
/*比例计算宽高，iPhone 6 尺寸基准*/
+(CGFloat)ratioWidth:(CGFloat)f
{
    return   f/RWidth*PhoneScreen_WIDTH;
}
+(CGFloat)ratioHeight:(CGFloat)f
{
    return  f/RHeight*PhoneScreen_HEIGHT;
}
+(void)fontFamilyNames{
    // 遍历获取字体名称
    for(NSString *fontFamilyName in [UIFont familyNames])
    {
        NSLog(@"family:'%@'",fontFamilyName);
        for(NSString *fontName in [UIFont fontNamesForFamilyName:fontFamilyName])
        {
            NSLog(@"\tfont:'%@'",fontName);
        }
        NSLog(@"-------------");
    }
}
@end
